﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Debug = UnityEngine.Debug;

/// <summary>
/// ECS组件基类
/// </summary>
public abstract class ECSCompoentBase 
{
    #region 更改为结构体不太合适，后期考虑将常copy的进行更该为struct
    /// <summary>
    /// 每种类型组件都有自己单独的哈希（只区分类型）
    /// </summary>
    public static Int16 hashCode;

    private ECSEntityBase m_entity;
    /// <summary>
    /// 获取组件所处实体
    /// </summary>
    public ECSEntityBase Entity
    {
        get
        {
            if (m_entity != null)
            {
                return m_entity;
            }
            Debug.LogError("获取的实体为null,哈希为" + hashCode);
            throw new Exception("获取的实体为null,组件哈希为" + hashCode);
            //return null;
        }
        set { m_entity = value; }
    }

    private ECSWorldBase m_world;
    /// <summary>
    /// 获取组件所处世界
    /// </summary>
    public ECSWorldBase World
    {
        get
        {
            if (m_world != null)
            {
                return m_world;
            }
            Debug.LogError("获取的世界为null,组件哈希为" + hashCode);
            throw new Exception("获取的世界为null,组件哈希为" + hashCode);
            // return null;
        }
        set { m_world = value; }
    }



    /// <summary>
    /// 组件初始化方法
    /// </summary>
    public abstract void Init();
   

    /// <summary>
    /// 返回组件哈希
    /// </summary>
    /// <returns></returns>
    public abstract int ToHash();
    /// <summary>
    /// 组件移除时
    /// </summary>
    public virtual void GoNull()
    {
        m_entity = null;
        m_world = null;
    }


    #endregion

}

